package com.zyx.javademo.enumdemo;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @author Yaxi.Zhang
 * @since 2021/6/29 11:11
 * desc: 含有星期信息的weekday枚举类
 */
enum NumberedWeekday {
    // 星期字段
    MON(1, "星期一"), TUE(2, "星期二"), WED(3, "星期三"),
    THU(4, "星期四"), FRI(5, "星期五"), SAT(6, "星期六"), SUN(0, "星期日");

    public final int dayValue;
    private final String chinese;

    NumberedWeekday(int dayValue, String chinese) {
        this.dayValue = dayValue;
        this.chinese = chinese;
    }

    public static NumberedWeekday getEnumByDay(int value) {
        return Arrays.stream(values()).filter(it -> it.dayValue == value).findFirst().orElse(null);
    }

    @Override
    public String toString() {
        // 默认情况下，对枚举常量调用toString()会返回和name()一样的字符串。但是，toString()可以被覆写，而name()则不行。我们可以给Weekday添加toString()方法
        return this.chinese;
    }
}
